#include<bits/stdc++.h>
using namespace std;
const int N = 50005;
map<int,int>mp[N];
int n,m;
int B;
queue< pair<int,int> >que;
long long ans = 0;
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
int main()
{
    freopen("grid.in","r",stdin);
    freopen("grid.out","w",stdout);
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m>>B;
    while(B--)
    {
        int x,y;cin>>x>>y;
        mp[x][y] += 2;
        if(mp[x][y] == 2) que.push(make_pair(x,y));
    }
    while(!que.empty())
    {
        auto p = que.front();que.pop();ans++;
        for(int i = 0;i < 4;i++)
        {
            int x = p.first+dir[i][0],y = p.second+dir[i][1];
            mp[x][y]++;
            if(mp[x][y] == 2)
            {
                que.push(make_pair(x,y));
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}